var BSTMG = BSTMG || {};
BSTMG.payment = {
		init: function(){
			var that = this;
			//线下支付列表查询 
			that.paymentListReq();
			//分页功能
			
		},
		paymentListReq: function(){
			
			BSTMG.common.hjhPages("/sysAdmin/payment/paymentList/search",function(data){
				var paymentList = data.paymentList;
				var $tbody = $("#paymentList tbody");
				var $tr = '';
				if(paymentList.length > 0) {
					for(var i=0;i<paymentList.length;i++){
						var paymentInfo = paymentList[i];
						var remitTime;
						if(paymentInfo.remitTime){
							remitTime = new Date(paymentInfo.remitTime);
							remitTime = toDate(remitTime, "yyyy-MM-dd hh:mm:ss");
						}else{
							remitTime = '';
						}
							
						$tr += '<tr class="odd">';
						$tr += '<td>'+(i+1)+'</td>';
						$tr += '<td>'+paymentInfo.paymentNum+'</td>';
						$tr += '<td>'+setDealType(paymentInfo.dealType)+'</td>';
						$tr += '<td>'+BSTMG.tools.checkNull(paymentInfo.remitCompany)+'</td>';
						$tr += '<td>'+BSTMG.tools.checkNull(paymentInfo.remitBank)+'</td>';
						$tr += '<td>'+BSTMG.tools.checkNull(parseFloat(paymentInfo.remitMoney).toFixed(2))+'</td>';
						$tr += '<td>'+remitTime+'</td>';
						$tr += '<td>'+setPaymentType(paymentInfo)+'</td>';
						$tr += '<td><a class="btn btn-primary '+ ((paymentInfo.paymentState == 0 || paymentInfo.isCancel == 1 ) ? 'disabled':'') +'" href="/sysAdmin/payment/paymentDetail/'+paymentInfo.paymentId+'">'+setPaymentButton(paymentInfo)+'</a></td>';
						$tr += '</tr>';
						
					}
					$tbody.html($tr);
				}else {
					var $tr = '<tr class="odd"><td colspan="8">暂无数据！</td></tr>';
					$tbody.html($tr);
				}
			});
		}
			
}

$(function(){
	BSTMG.payment.init();
});

//审核操作
function toAudit(paymentId,paymentState,pstate){
	if(pstate == 2){
		BSTYUN.dialog.warn('已审批过！不能重复审批！');
		return;
	}else if(pstate == 3){
		BSTYUN.dialog.warn('已审批过！不能重复审批！');
		return;
	}
	$.ajax({
		type : "POST",
		url : "/sysAdmin/operate/payment/updatePayment",
		async : false,
		data:{
			paymentId:paymentId,
			paymentState:paymentState
		},
		success:function(data){
			if(data) {
				BSTYUN.dialog.ok("操作成功！",function(){
					location.href = "/sysAdmin/payment/paymentList";
				});
			}else {
				BSTYUN.dialog.warn("操作失败！");
			}
		}
	})
}
//设置交易类型
function setDealType(dealType){
	if (dealType == "1") {
		return "充值";
	} else if (dealType == "2") {
		return "消费";
	} else if (dealType == "3") {
		return "提现";
	} else if (dealType == "4") {
		return "退款";
	} else if (dealType == "5") {
		return "其他";
	}
}

//设置凭证上传状态
function setPaymentType(paymentInfo){
	var paymentState = paymentInfo.paymentState;
	var isCancel = paymentInfo.isCancel;
	if(isCancel == "0" || isCancel == null){
		if (paymentState == "0") {
			return "未上传";
		} else if (paymentState == "1") {
			return "已上传";
		} else if(paymentState == "2"){
			return "审核通过";
		} else if(paymentState == "3"){
			return "审核退回";
		}
	}else{
		return "已取消";
	}
	
}

//设置操作按钮
function setPaymentButton(paymentInfo){
	var paymentState = paymentInfo.paymentState;
	var isCancel = paymentInfo.isCancel;
	if(isCancel == "0" || isCancel == null){
		if (paymentState == "0") {
			return "等待上传";
		} else if (paymentState == "1") {
			return "待审核";
		} else if(paymentState == "2"){
			return "审核通过";
		} else if(paymentState == "3"){
			return "退回待审核";
		}
	}else{
		return "已取消";
	}
}




